package eCheque;

import java.io.*;

public class DigitalCertificateIO {

	public void SaveDC(DigitalCertificate digitalCertificate, String filePath)
			throws IOException {
		FileOutputStream fileOutputStream = null;
		ObjectOutputStream objectOutputStream = null;
		try {
			fileOutputStream = new FileOutputStream(new File(filePath));
			objectOutputStream = new ObjectOutputStream(fileOutputStream);
			objectOutputStream.writeObject(digitalCertificate);
		} finally {
			EChequeUtils.safeClose(objectOutputStream);
			EChequeUtils.safeClose(fileOutputStream);
		}
	}

	public DigitalCertificate readDigitalCertificate(String filePath)
			throws IOException, ClassNotFoundException, ClassCastException {
		ObjectInputStream objectInputStream = null;
		FileInputStream fileInputStream = null;
		try {
			fileInputStream = new FileInputStream(new File(filePath));
			objectInputStream = new ObjectInputStream(fileInputStream);
			DigitalCertificate dc = (DigitalCertificate) objectInputStream
					.readObject();
			return dc;
		} finally {
			EChequeUtils.safeClose(fileInputStream);
			EChequeUtils.safeClose(objectInputStream);
		}
	}

	/** Creates a new instance of SaveDC */
	public DigitalCertificateIO() {

	}

}